﻿#pragma once

#include "MirControl.h"
#include "MirLabel.h"
#include "MirButton.h"
#include <string>
#include <vector>
#include <any>
#include "../../tangible_event.h"

using namespace Client::MirGraphics;

namespace Client::MirControls
{
    class MirDropDownBox : public MirControl
    {
    private:
        MirLabel *_label;
        MirButton *_DropDownButton;
        std::vector<MirLabel*> _Option = std::vector<MirLabel*>(5);
        MirButton *_ScrollUp, *_ScrollDown, *_ScrollPosition;

    public:
        int _SelectedIndex = -1;
        int _WantedIndex = -1;
        int MinimumOption = 0;
        int ScrollIndex = 0;
        int OrigHeight = 0;
        long long LastMouseLeave = 0;
    private:
        std::vector<std::string> _Items = std::vector<std::string>();
    public:
        TangibleEvent<EventHandler> *ValueChanged = new TangibleEvent<EventHandler>();

        virtual ~MirDropDownBox()
        {
            delete _label;
            delete _DropDownButton;
            delete _ScrollUp;
            delete _ScrollDown;
            delete _ScrollPosition;
        }

        int getSelectedIndex() const;
        void setSelectedIndex(int value);

        std::vector<std::string> getItems() const;
        void setItems(const std::vector<std::string> &value);

        #pragma region Back Color

    protected:
        void OnBackColourChanged() override;

        #pragma endregion

        #pragma region Size
        void OnSizeChanged() override;
        #pragma endregion

        #pragma region Enabled

        void OnEnabledChanged() override;

        #pragma endregion

    public:
        MirDropDownBox();

    private:
        void MirDropDownBox_BeforeDraw(std::any sender, EventArgs *e);

    protected:
        void OnMouseLeave() override;

    public:
        void SelectOption(int index);

        void ItemsChanged();
        void Update();
        void DropDownClick();
        void OpenDropDown();
        void CloseDropDown();
        void ScrollUp();
        void ScrollDown();
    private:
        void ScrollPosition(std::any sender, MouseEventArgs *e);

        #pragma region Disposable
    protected:
        void Dispose(bool disposing) override;
        #pragma endregion
    };
}
